package com.xfxz.merchant.view.homepage;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;

import com.xfxz.merchant.R;
import com.xfxz.merchant.customview.MyGridView;
import com.xfxz.merchant.myapplication.BaseActivity;
import com.xfxz.merchant.presenter.PresenterImpl;
import com.xfxz.merchant.view.MainView;
import com.xfxz.merchant.view.attention.AttentionCollectionActivity;
import com.xfxz.merchant.view.coupon.CouponManagerActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends BaseActivity implements MainView, AdapterView.OnItemClickListener {
    private PresenterImpl mPresenter;

    private String[] iconName = {"商品管理", "订单管理", "关注/收藏管理", "优惠券管理", "库存管理",
            "客服", "店铺管理", "更多"};
    private int[] icon = {R.drawable.icon_main_goods_manage, R.drawable.icon_main_order_manage,
            R.drawable.icon_main_collect_manage, R.drawable.icon_main_coupon_manage, R.drawable.icon_main_stock_manage,
            R.drawable.icon_main_online, R.drawable.icon_main_shop_manage, R.drawable.icon_main_more};
    private MyGridView mGridView;
    private SimpleAdapter mSimpleAdapter;
    private ArrayList<Map<String, Object>> mDataMyGv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BaseSetContentView(R.layout.activity_main);
        setBarTitle("店铺名称");
        setBarLeftText("店铺",View.VISIBLE);
        mGridView = (MyGridView) findViewById(R.id.mgv_main);
        mDataMyGv = new ArrayList<>();
        mSimpleAdapter = new SimpleAdapter(this, mDataMyGv, R.layout.item_grid_ivtv,
                new String[]{"image", "text"}, new int[]{R.id.iv_item_gv_ivtv, R.id.tv_item_gv_ivtv});
        mGridView.setAdapter(mSimpleAdapter);
        for (int i = 0; i < icon.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("image", icon[i]);
            map.put("text", iconName[i]);
            mDataMyGv.add(map);
        }
        mSimpleAdapter.notifyDataSetChanged();

        initClickListener();
    }

    private void initClickListener() {
        mGridView.setOnItemClickListener(this);
    }

    @Override
    public void onBarBackClickListener() {
        super.onBarBackClickListener();

    }

    @Override
    public void setData(Object o) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0: // 商品管理
                break;
            case 2: // 关注收藏管理
                startActivity(new Intent(this,AttentionCollectionActivity.class));
                break;
            case 3: // 优惠券管理
                startActivity(new Intent(this,CouponManagerActivity.class));
                break;
        }
    }
}
